<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key">

  <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>


  <xsl:variable name="UnitCount" select="count(/ProjectDataSet/Project/BacklogItemUnit[Type != 6])" />
  <xsl:variable name="SprintCount" select="count(/ProjectDataSet/Project/Sprint)" />

  <xsl:include href="include/Slices.xslt"/>

  <xsl:variable name="plannedSprints" select="/ProjectDataSet/Project/Sprint[SprintNumber &lt;= /ProjectDataSet/Project/Baseline]"/>


  <xsl:template match="/">
    <FlowDocument
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key"
      xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls;assembly=BadHabit.Factory.Windows"
      
      PageWidth="21cm"
      PagePadding="60,40,40,40"
      PageHeight="29.7cm"
      ColumnWidth="21 cm">


      <xsl:call-template name="StyleSettings"/>

      <xsl:call-template name="Header">
        <xsl:with-param name="type" select="'Project Deliveries'"/>
      </xsl:call-template>

      

          <!-- SPRINT HEADERS -->
      <xsl:for-each select="/ProjectDataSet/Project/Sprint[SprintNumber &lt; /ProjectDataSet/Project/Baseline]">
        <xsl:sort select="SprintNumber" data-type="number" />

        <xsl:variable name="sprintUId" select="SprintUId"/>
        <xsl:variable name="sprintNumber" select="SprintNumber"/>

        <Paragraph Style="{{StaticResource TitleParagraph}}">
          
            Items already deliveried <xsl:value-of select="ExpirationDateString" /> (<xsl:value-of select="$sprintNumber" />&#186; Sprint)
          
        </Paragraph>

        <xsl:call-template name="DeliveryItems">
          <xsl:with-param name="sprintUId" select="$sprintUId" />
          <xsl:with-param name="plannedItems" select="/ProjectDataSet/Project/BacklogItem[DeliverySprintNumber=$sprintNumber and Status=2]" />
        </xsl:call-template>

      </xsl:for-each>

      <xsl:for-each select="/ProjectDataSet/Project/Sprint[SprintNumber &gt;= /ProjectDataSet/Project/Baseline]">
        <xsl:sort select="SprintNumber" data-type="number" />

        <xsl:variable name="sprintUId" select="SprintUId"/>
        <xsl:variable name="sprintNumber" select="SprintNumber"/>

        <Paragraph Style="{{StaticResource TitleParagraph}}">
          
            Planned delivery for <xsl:value-of select="ExpirationDateString" /> (<xsl:value-of select="$sprintNumber" />&#186; Sprint)
          
        </Paragraph>

        <xsl:call-template name="DeliveryItems">
          <xsl:with-param name="sprintUId" select="$sprintUId" />
          <xsl:with-param name="plannedItems" select="/ProjectDataSet/Project/BacklogItem[DeliverySprintNumber=$sprintNumber]" />
        </xsl:call-template>

      </xsl:for-each>



    </FlowDocument>
  </xsl:template>


</xsl:stylesheet>